import { objDeepCopy,getDateString } from "@/assets/js/common.js";

let Controller = {
	created() {
		this.init();
	},
	mounted() {
		
	},
	methods: {
		init() {
			this.getAllMsg(this,this.$route.query.number);
		},
		//获取列表
		getAllMsg(that,orderNumber){
			var apiTest = this.apiTest;
			this.$ajax({
					method: 'post',
					url:apiTest+'/supplier/whWarehouseDetail/outAndInDetails',
					data:{
						condition:{
							number:orderNumber  //单号
						}
					}
			    }).then((res)=>{
					console.log(res);
					that.Model.tab1TableData = [];
					that.Model.tab2TableData = [];
					var data = res.data;
					if(data.status == 200){
						var obj = {};
						var result = data.result;
						switch (result.status){
							case '待制证':
								that.Model.refundStep.activeStep = 1
								break;
							case '制证中':
								that.Model.refundStep.activeStep = 2
								break;
							case '已制证':
								that.Model.refundStep.activeStep = 3
								break;
							case '已完结':
								that.Model.refundStep.activeStep = 4
								break;
							case '已作废':
								that.Model.refundStep.activeStep = 5
								break;
							default:
								break;
						}
						/* tabFormInline */
						this.Model.tabFormInline = [
							{
								label: '认证单号',
								value: result.number,
							},
							{
								label: '单据状态',
								value: result.status,
							},
						]
						/* tableFormInline */
						var inNumber;
						if(result.authGoodsList){
							inNumber = result.authGoodsList.length;//认证出库数量
						}
						
						this.Model.tableFormInline = [
							{
								label: '认证单类型',
								value: result.authenticationBillTyle,
							},
							{
								label: '认证机构',
								value: result.authenticationOrganization,
							},
							{
								label: '认证类型',
								value: result.authenticationTyle,
							},
							{
								label: '认证原因',
								value: result.inWarehouseName,
							},
							{
								label: '创建人',
								value: result.createName,
							},
							{
								label: '操作人',
								value: result.checkName,
							},
							{
								label:'认证出库数量',
								value: inNumber,
							},
							{
								label:'认证入库数量',
								value: result.authInCount,
							},
							{
								label:'已导入数量',
								value: result.importedCount,
							},
						]
						if(result.authGoodsList){
							var listData = result.authGoodsList;
							for (var i = 0; i < listData.length; i++) {
								obj = objDeepCopy(listData[i]);
								that.Model.tab1TableData.push(obj)
							}
						}
						
						/* 操作记录 */
						var logObj;
						var logList = result.whWarehouseLogList;
						for (let i = 0; i < logList.length; i++) {
							logObj = objDeepCopy(logList[i]);
							that.Model.tab2TableData.push(logObj)
						}
					}else{
			
					}
			
				});
		},
		//
		//
		onDialogEdit() {
			
		},
		//
		toggleTableDetail() {
			
		},
		//返回上一级
		toInside() {
			this.$router.push({
				path:'certificationSheetList',
				query:{
					
				}
			});
		},
		toggleTableDetail(val) {
			const obj = this.Model[val];
			if (obj.flag === true) {
				this.Model[val].src = require('@/assets/img/icon_collapse.png');
				this.Model[val].flag = false;
			} else {
				this.Model[val].src = require('@/assets/img/icon_unfold.png');
				this.Model[val].flag = true;
			}
		},
		onDialogEdit(flag, val) {
// 			this.Model.editDialogFlag = flag;
// 			var saleId = this.Model.saleId;	
// 			if (flag === false) return;
// 			const arr = this.Model[val];
// 			this.Model.editDialogType = val;
// 			this.Model.editDialogFormData = _.cloneDeep(arr);
		},
		selectedHighlight(data) {
			// 如果选中则添加高亮样式
			if (this.Model.TableSelectData.indexOf(data.row) > -1) {
				return {
					"background-color": "#FEF6EE"
				};
				return {}
			}
		},
		//合计
		getSummaries(param) {
			var that = this;
			const { columns, data } = param;
			const sums = [];
			columns.forEach((column, index) => {
		    if (index === 0) {
		      sums[index] = '总价';
		      return;
		    }else if(index === 6 || index === 7 || index === 8 || index === 10) {
					  const values = data.map(item => Number(item[column.property]));
					  sums[index] = values.reduce((prev, curr) => {
					    const value = Number(curr);
					    if (!isNaN(value)) {
					      return prev + curr;
					    } else {
					      return prev;
					    }
					  }, 0);
					  if(index === 10){
						that.Model.totleGoodCount = sums[index];
					  }else{
						
					  }
					  
				  }else{
					sums[index] = '/';
				  }
		  });
		
		  return sums;
		},
		warehousing(row) {
			this.Model.warehousingDialogStatus = row.status;
			this.Model.warehousingDialogFlag = true;
		},
		handleSelectionChange(val) {
			console.log(val);
			this.Model.addGiftsSelectData = val
		  
		},
		handleCurrentChange(val) {
			this.Model.pager.params.pageIndex = val;
		},
		handleSizeChange(val) {
			this.Model.pager.params.pageSize = val;
		},
		cardClick(color) {
			this.Model.cardSelected = color;
		},
		showChild(val) {
			this.Model.searchFromData = val;
		},
		toSearch(val) {
			console.log(val)
		},
		toClear(val) {
			this.Model.searchFromData = this.Model.defaultSearchFromData;
		},
		toExport(val) {
		  console.log(val);
		},
		onTabChange(val) {
			console.log(val, this.Model.activeTab)
			switch (val) {
				case 1:
					break;
				case 2:
					break;
				case 3:
					break;
			}
		},
		tips(that,type,message) {
			that.$message({
				message: message,
				type: type
			});
		},
	},
	watch:{
		$route:{
		　　　handler(newValue, oldValue) {
				if(newValue.query.number) {
					this.getAllMsg(this,this.$route.query.number);
				}
				
		　　　},
		　　　deep: true
		},
  	
	},
	filters:{
		objFilters:function(value){
			
		}
	}
}
export default Controller;
